import axios from "axios"
import qs from "querystring"

// 请求拦截
axios.interceptors.request.use(config=>{
    return config
})
// 响应拦截
axios.interceptors.response.use(res=>{
    // 统一打印
    console.group("本次请求地址："+res.config.url)
    console.log(res);
    console.groupEnd()

    return res
})

// 封装get
export function get(url,params = {}) {
    return axios({
        url,
        params
    })
}

// 封装post
export function post(url,params={},isFile=false) {
    let data = null;
    if(isFile){
        data = new FormData()

        Object.keys(params).forEach(key=>{
            data.append(key,params[key])
        })``
    }else{
        data=qs.stringify(params)
    }
    return axios({
        url,
        data,
        method:"post"
    })
}